package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.StaffInfoVo;
import org.dromara.nursing.domain.bo.StaffInfoBo;
import org.dromara.nursing.service.IStaffInfoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 员工基本信息
 *
 * @author Xue
 * @date 2025-04-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/staffInfo")
public class StaffInfoController extends BaseController {

    private final IStaffInfoService staffInfoService;

    /**
     * 查询员工基本信息列表
     */
    // @SaCheckPermission("nursing:staffInfo:list") // 已移除权限验证
    @GetMapping("/list")
    public TableDataInfo<StaffInfoVo> list(StaffInfoBo bo, PageQuery pageQuery) {
        return staffInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出员工基本信息列表
     */
    // @SaCheckPermission("nursing:staffInfo:export") // 已移除权限验证
    @Log(title = "员工基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(StaffInfoBo bo, HttpServletResponse response) {
        List<StaffInfoVo> list = staffInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "员工基本信息", StaffInfoVo.class, response);
    }

    /**
     * 获取员工基本信息详细信息
     *
     * @param staffId 主键
     */
    // @SaCheckPermission("nursing:staffInfo:query") // 已移除权限验证
    @GetMapping("/{staffId}")
    public R<StaffInfoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long staffId) {
        return R.ok(staffInfoService.queryById(staffId));
    }

    /**
     * 新增员工基本信息
     */
    // @SaCheckPermission("nursing:staffInfo:add") // 已移除权限验证
    @Log(title = "员工基本信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody StaffInfoBo bo) {
        return toAjax(staffInfoService.insertByBo(bo));
    }

    /**
     * 修改员工基本信息
     */
    // @SaCheckPermission("nursing:staffInfo:edit") // 已移除权限验证
    @Log(title = "员工基本信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody StaffInfoBo bo) {
        return toAjax(staffInfoService.updateByBo(bo));
    }

    /**
     * 删除员工基本信息
     *
     * @param staffIds 主键串
     */
    // @SaCheckPermission("nursing:staffInfo:remove") // 已移除权限验证
    @Log(title = "员工基本信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{staffIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] staffIds) {
        return toAjax(staffInfoService.deleteWithValidByIds(List.of(staffIds), true));
    }
}
